package com.nyist.myticket.core.quartz.job;

import com.nyist.myticket.biz.service.ToMailService;
import com.nyist.myticket.core.utils.GetWeather;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Map;

/**
 * @author yangxiaogen
 * @date 2020/12/25 14:44
 */
public class MailToWeatherScheduler extends QuartzJobBean {

    private static Logger logger = LoggerFactory.getLogger(GetWeather.class);

    @Autowired
    private ToMailService toMailService;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        String subject = "温馨提醒 - 天气";
        //StringBuilder text = new StringBuilder();
        //text.append("您所在的天气是:"+"10摄氏度");

        GetWeather getWeather = new GetWeather();
        Map<String, Object> objectMap = getWeather.getConnect("411500");
        logger.info("发送内容为:----\n"+objectMap.toString());
        toMailService.quartzToMail(subject,objectMap.toString());
    }
}
